Skip to content

inspector: add --cond to node inspect probe mode#64328

Open
joyeecheung wants to merge 2 commits into
nodejs:mainfrom
joyeecheung:probe-cond
Open

inspector: add --cond to node inspect probe mode#64328
joyeecheung wants to merge 2 commits into
nodejs:mainfrom
joyeecheung:probe-cond

Conversation

@joyeecheung

Copy link
Copy Markdown
Member

On a hot path, the probe can record every hit and require filtering afterwards. This patch adds a per-probe --cond <expr> option that allows limiting the hit to only when the expression is truthy at the probe location. V8 evaluates it as the breakpoint's native condition, so the target is not paused when it does not hold, and a condition that throws is treated as false. Since in CDP, a location can only carry one breakpoint per URL pattern, probes sharing a location must share one condition (or none). Conflicting conditions are rejected.

Example:

// app.js
let total = 0;
for (let i = 0; i < 10; i++) {
  total += i;  // line 4
}
$ out/Release/node inspect --probe app.js:4 --expr 'total' \
                           --cond 'i % 3 === 0' app.js
Hit 1 at file:///path/to/app.js:3:3
  total = 0
Hit 2 at file:///path/to/app.js:3:3
  total = 3
Hit 3 at file:///path/to/app.js:3:3
  total = 15
Hit 4 at file:///path/to/app.js:3:3
  total = 36
Completed

Refs: #63646

@nodejs-github-bot nodejs-github-bot added debugger Issues and PRs related to the debugger subsystem. needs-ci PRs that need a full CI run. labels Jul 6, 2026
On a hot path, the probe can record every hit and require
filtering afterwards. This patch adds a per-probe `--cond <expr>`
option that allows limiting the hit to only when the expression
is truthy at the probe location. V8 evaluates it as the breakpoint's
native condition, so the target is not paused when it does not hold,
and a condition that throws is treated as false. Since in CDP,
a location can only carry one breakpoint per URL pattern,
probes sharing a location must share one condition (or none).
Conflicting conditions are rejected.

Example:

```js
// app.js
let total = 0;
for (let i = 0; i < 10; i++) {
  total += i;  // line 4
}
```

```
$ out/Release/node inspect --probe app.js:4 --expr 'total' \
                           --cond 'i % 3 === 0' app.js
```

```
Hit 1 at file:///path/to/app.js:3:3
  total = 0
Hit 2 at file:///path/to/app.js:3:3
  total = 3
Hit 3 at file:///path/to/app.js:3:3
  total = 15
Hit 4 at file:///path/to/app.js:3:3
  total = 36
Completed
```

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment thread lib/internal/debugger/inspect_probe.js
Comment thread doc/api/debugger.md Outdated
@joyeecheung

Copy link
Copy Markdown
Member Author

Thanks for the review, I think I've addressed the comments. @jasnell can you take another look? Thanks!

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 9, 2026
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.25%. Comparing base (e6a8d06) to head (2881e97).
⚠️ Report is 304 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64328      +/-   ##
==========================================
- Coverage   92.01%   90.25%   -1.76%     
==========================================
  Files         379      741     +362     
  Lines      166972   241221   +74249     
  Branches    25554    45436   +19882     
==========================================
+ Hits       153639   217716   +64077     
- Misses      13041    15077    +2036     
- Partials      292     8428    +8136     
Files with missing lines Coverage Δ
lib/internal/debugger/inspect.js 94.00% <100.00%> (+1.40%) ⬆️
lib/internal/debugger/inspect_helpers.js 97.40% <100.00%> (+0.14%) ⬆️
lib/internal/debugger/inspect_probe.js 81.99% <100.00%> (+2.37%) ⬆️

... and 542 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 9, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Issues and PRs related to the debugger subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants